import { t } from "@/locales";
import {FormRule, PrimaryTableCol, SelectProps, Icon, Tag} from "tdesign-vue-next";

/**
 * 搜索表单项
 */
export const searchParams: SearchParamsProps[] = [
    {
        label: t('pages.sysPermission.name'),
        key: 'name',
    },
    {
        label: t('pages.sysPermission.englishName'),
        key: 'englishName',
    },
    {
        label: '',
        key: 'type',
        hide: true,
        defaultValue: 0,
    },
    {
        label: '',
        key: 'tree',
        hide: true,
        defaultValue: true,
    }
];

/**
 * 表格列
 */
export const columns: PrimaryTableCol[] = [
    {
        title: t('pages.sysPermission.name'),
        ellipsis: true,
        align: 'center',
        colKey: 'name',
    },
    {
        title: t('pages.sysPermission.path'),
        align: 'center',
        colKey: 'path',
    },
    {
        title: t('pages.sysPermission.englishName'),
        ellipsis: true,
        align: 'center',
        colKey: 'englishName',
    },
    {
        title: t('pages.sysPermission.code'),
        ellipsis: true,
        align: 'center',
        colKey: 'code',
    },
    {
        title: t('pages.sysPermission.outerChain'),
        ellipsis: true,
        align: 'center',
        colKey: 'outerChain',
        cell: (h, {row}) => h(Tag, { theme: row.outerChain == 0 ? 'warning' : 'success' }, t(`components.YesNo.${row.outerChain == 0 ? 'no' : 'yes'}`))
    },
    {
        title: t('pages.sysPermission.icon'),
        ellipsis: true,
        align: 'center',
        colKey: 'icon',
        cell: (h, {row}) => h(Icon, { name: row.icon })
    },
    {
        title: t('pages.sysPermission.sort'),
        ellipsis: true,
        align: 'center',
        colKey: 'sort',
    },
    {
        title: t('pages.sysPermission.remarks'),
        ellipsis: true,
        align: 'center',
        colKey: 'remarks',
    },
];

/**
 * 表单校验规则
 */
export const rules: Record<string, FormRule[]> = {
    type: [{required: true, message: t('pages.sysPermission.required.type'), type: 'error', trigger: 'all'}],
    path: [{required: true, message: t('pages.sysPermission.required.path'), type: 'error', trigger: 'blur'}],
    parentId: [{required: true, message: t('pages.sysPermission.required.parentId'), type: 'error', trigger: 'all'}],
    name: [{required: true, message: t('pages.sysPermission.required.name'), type: 'error', trigger: 'blur'}],
    englishName: [{required: true, message: t('pages.sysPermission.required.englishName'), type: 'error', trigger: 'blur'}],
    code: [{required: true, message: t('pages.sysPermission.required.code'), type: 'error', trigger: 'blur'}],
    sort: [{required: true, message: t('pages.sysPermission.required.sort'), type: 'error', trigger: 'blur'}],
}

export const typeOptions: SelectProps['options'] = [
    {
        label: t('pages.sysPermission.typeOption.parent'),
        value: 0
    },
    {
        label: t('pages.sysPermission.typeOption.children'),
        value: 1
    },
    {
        label: t('pages.sysPermission.typeOption.perms'),
        value: 2
    },
];

export const YesNoOptions: SelectProps['options'] = [
    {
        label: t('components.YesNo.no'),
        value: 0
    },
    {
        label: t('components.YesNo.yes'),
        value: 1
    },
];
